<?php

namespace app\common\model\banxi\learn;

use app\common\model\common\BaseModel;
use think\model\concern\SoftDelete;

/**
 * 阅读理解文章扩展表
 */
class LearnReadingArticleExtend extends BaseModel
{
    use SoftDelete;

    protected $name = 'banxi_learn_reading_article_extend';

    protected $autoWriteTimestamp = true;

    protected $deleteTime = 'del';

    protected $defaultSoftDelete = 0;

    protected $append = [
        'isAiError',
        'isSearchDetail'
    ];

    protected $type = [
        'id' => 'string',
        'del' => 'string',
        'readingArticleId' => 'string',
        'createTime' => 'timestamp:Y-m-d H:i:s',
        'updateTime' => 'timestamp:Y-m-d H:i:s',
    ];

    //-----------------------------------------------------------------------------------
    //｜                                   获取器                                       ｜
    //-----------------------------------------------------------------------------------
    public function getIsAiErrorAttr($value, $data): bool
    {
        return ($data['aiQuestionStatus'] == '3' || $data['aiOtherStatus'] == '3');

    }

    public
    function getIsSearchDetailAttr($value, $data): bool
    {
        return ($data['aiQuestionStatus'] == '2' && $data['aiOtherStatus'] == '2');
    }

    //-----------------------------------------------------------------------------------
    //｜                                   处理方法                                       ｜
    //-----------------------------------------------------------------------------------

    /**
     * 根据阅读文章ID获取扩展信息
     * @param int $readingArticleId 阅读文章ID
     * @return array|null 扩展信息记录
     */
    public function getByReadingArticleId($readingArticleId)
    {
        // 查询阅读文章扩展信息记录
        return $this->where('reading_article_id', $readingArticleId)->find();
    }

    //-----------------------------------------------------------------------------------
    //｜                                   模型关联                                       ｜
    //-----------------------------------------------------------------------------------


}